#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

int testcutPurseEffect(struct gameState *state) {
	int handCnt[3], coinCount[3], i;
	//put cards in hands 
	state->hand[0][0] = gold;
	state->hand[0][1] = cutpurse;
	state->hand[0][2] = smithy;
	state->hand[0][3] = copper;
	state->hand[0][4] = adventurer;
	
	state->handCount[0] = 5;
	
	state->hand[1][0] = village;
	state->hand[2][0] = village;
	state->hand[1][1] = steward;
	state->hand[2][1] = steward;
	state->hand[1][2] = remodel;
	state->hand[2][2] = remodel;
	state->hand[1][3] = copper;
	state->hand[2][3] = gold;
	state->hand[1][4] = copper;
	state->hand[2][4] = silver;
	
	state->handCount[1] = 5;
	state->handCount[2] = 5;
	
	for (i=0;i<state->numPlayers;i++) {
		updateCoins(i,state,0);
		coinCount[i] = state->coins;
		handCnt[i] = state->handCount[i];
	}
	//play card
	cardEffect(cutpurse, 0, 0, 0, state, 1, 0);
	//check that cutPurse is no longer in that position
	assert(cutpurse != state->hand[0][1]);
	printf("\tCard was discarded");
	//handCount should be one less (spent cutPurse) of current, minus coppers for others
	assert(state->handCount[0] == handCnt[0] - 1);
	assert(state->handCount[1] == handCnt[1] - 1);
	assert(state->handCount[2] == handCnt[2]);
	printf(", handCounts correct");
	//coin Count should be 2 greater than before for current, two less for player 1, same for p2
	updateCoins(0,state,0);
	assert(state->coins = coinCount[0] + 2);
	updateCoins(1,state,0);
	assert(state->coins = coinCount[1] - 1);
	updateCoins(2,state,0);
	assert(state->coins = coinCount[2]);
	printf(", coin count was adjusted correctly\n");
	return 0;
}

int main() {
    
    int seed = 1000;
    int numPlayer = 3;
    
	struct gameState G;
	struct gameState *state = &G;
	int k[10] = {council_room, smithy, steward, remodel, village, minion, mine, cutpurse, 
		   sea_hag, tribute};

	initializeGame(numPlayer, k, seed, &G);
	printf("Testing cutPurseEffect():\n");
	testcutPurseEffect(state);
	
	printf("   cutPurseEffect() Passed all tests!\n");
	

    return 0;
}

